/*
3031. 二进制倒置
Time limit per test: 2.0 seconds

Memory limit: 256 megabytes

给定一个整数 n(0≤n≤10^100)、将 n 的 334 位二进制表示形式（不包括开头可能的值为 0 的位，n=0 表示为 1 位 0）前后倒置，输出倒置后的二进制数对应的整数。

例如：n=10，其二进制表示为 (330 个 0)1010，倒置后为 0101，对应输出就是 5。

Input
第 1 行：一个整数 T (1≤T≤10) 为问题数。

接下来共 T 行整数，对应每个问题有 1 行，表示 n。

Output
对于每个问题，输出一行问题的编号（0 开始编号，格式：case #0: 等）。

然后对应每个问题在一行中输出结果。

Examples
input
3
10
0
10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
output
case #0:
5
case #1:
0
case #2:
7715442851596369463000695959966459436485038766875199595258933941809737
Hints
十进制10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000的334位二进制表示为：
0100100100100110101101001001011001010011000011011111001110101100001011001001111000010011000100110011100000101111110011100010101100111001000000100011100010000100011010011111001010101010110010010000110000100010101000001011101000111100010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000，
不包括开头的 1个0为：
100100100100110101101001001011001010011000011011111001110101100001011001001111000010011000100110011100000101111110011100010101100111001000000100011100010000100011010011111001010101010110010010000110000100010101000001011101000111100010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000，
倒置后为：
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010001111000101110100000101010001000011000010010011010101010100111110010110001000010001110001000000100111001101010001110011111101000001110011001000110010000111100100110100001101011100111110110000110010100110100100101101011001001001001，
对应十进制值为：
7715442851596369463000695959966459436485038766875199595258933941809737
*/

#include <stdio.h>
#include <string.h>

// 定义大整数结构
struct Big
{
    int data[500];
    int len;
};

// 把字符串转换为大整数
int strtobig(struct Big *big, char str[])
{
    big->len = strlen(str);
    for (int i=0;i<big->len;i++)
        big->data[i] = str[big->len - 1 - i] - '0';
    return 0;
}

// 把大整数转换为字符串
int bigtostr(char str[], struct Big *big)
{
    for (int i=big->len-1; i>=0; i--)
        str[big->len-1-i] = big->data[i] + '0';
    str[big->len] = '\0';
    return 0;
}

// 判断大整数是否为0
// 返回值：1-值是非0，0-0
int notzero(struct Big *big)
{
    if (big->len==1 && big->data[0]==0)
        return 0;
    else
        return 1;
}

// 大整数除以2
// 商保存在大整数中
// 返回余数
int bigdiv2(struct Big *big)
{
    int mod=0;
    for (int i=big->len-1; i>=0; i--)
    {

        mod = big->data[i] + mod * 10;
        big->data[i] = mod / 2;
        mod = mod % 2;
    }
    if (big->len >1 && big->data[big->len-1]==0)
        big->len --;
    return mod;
}

// 大整数增加1
int bigadd1(struct Big *big)
{
    int carry=0;
    big->data[0] ++;
    for (int i=0; i<big->len; i++)
    {
        carry = carry + big->data[i];
        big->data[i] = carry % 10;
        carry = carry / 10;
    }
    if (carry > 0)
    {
        big->data[big->len] = carry;
        big->len ++;
    }
    return 0;
}

// 大整数乘以2，积保存到大整数中
int bigmul2(struct Big *big)
{
    int carry=0;
    for (int i=0; i<big->len; i++)
    {
        carry = carry + big->data[i]*2;
        big->data[i] = carry % 10;
        carry = carry / 10;
    }
    if (carry > 0)
    {
        big->data[big->len] = carry;
        big->len ++;
    }
    return 0;
}

// 十进制大整数转换为二进制大整数
int dectobin(struct Big *bin, struct Big *dec)
{
    int len=0;
    if (!notzero(dec))
    {
        bin->len = 1;
        bin->data[0]=0;
        return 0;
    }
    while (notzero(dec))
    {
        bin->data[len++] = bigdiv2(dec);
    }
    bin->len = len;
    return 0;
}

// 二进制大整数转换为十进制大整数
int bintodec(struct Big *dec, struct Big *bin)
{
    if (!notzero(bin))
    {
        dec->len = 1;
        dec->data[0]=0;
        return 0;
    }
    dec->len = 1;
    dec->data[0] = 0;
    for (int i=bin->len-1; i>=0; i--)
    {
        bigmul2(dec);
        if (bin->data[i]==1)
            bigadd1(dec);
    }
    return 0;
}

// 二进制大整数逆序转换为十进制大整数
int backbintodec(struct Big *dec, struct Big *bin)
{
    if (!notzero(bin))
    {
        dec->len = 1;
        dec->data[0]=0;
        return 0;
    }
    dec->len = 1;
    dec->data[0] = 0;
    for (int i=0; i<bin->len; i++)
    {
        bigmul2(dec);
        if (bin->data[i]==1)
            bigadd1(dec);
    }
    return 0;
}

int main()
{
    char str[102];
    struct Big bigdec, bigbin;
    int qnum;   //问题数

    scanf("%d", &qnum);
    for (int i=0; i<qnum; i++)
    {
        scanf("%s", str);
        strtobig(&bigdec, str);
        dectobin(&bigbin, &bigdec);
        backbintodec(&bigdec, &bigbin);
        bigtostr(str, &bigdec);
        printf("case #%d:\n%s\n", i, str);
    }

    return 0;
}
